from django.conf.urls.defaults import *
from django.views.generic.list_detail import object_list
#from parameter.models import JrcSystem, JrcParameter
#from django.views.generic.create_update import delete_object, update_object
from django.views.generic.edit import DeleteView, CreateView, UpdateView
from django.views.generic import ListView
from jrcmodel.models import JrcSystem, JrcParameter, Market, Asset
from django.contrib.auth.decorators import login_required, permission_required
from portadmin.views import DeleteCstView, GetSystemListView, AddCstView, MarketView, ListMarketsView, CreateMarketView, UpdateMarketView, DeleteMarketView,\
    EditCstView, GetCstsListView, DeletePortfolioView, CreateParameterView,\
    UpdateParameterView
from jrcshared.models import JrcPermission


urlpatterns = patterns(
    "portadmin.views"
    , (r"^$", "csts", {"page": 1})
    , (r"^csts/$", "csts", {"page": 1})
    , (r"^(?P<page>\d+)/getcstsnew/$", GetCstsListView.as_view())
    , (r"^(?P<page>\d+)/csts/$", "csts")
    , (r"^cst/add/$", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, login_url = "/accounts/denied/")(AddCstView.as_view()))
    , (r"^cst/(?P<pk>\d+)/$", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, login_url = "/accounts/denied/")(EditCstView.as_view()))
    , (r"^csts/(?P<pk>\d+)/delete/$", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, login_url = "/accounts/denied/")(DeleteCstView.as_view()))
    , (r"^cst/(?P<pk>\d+)/view/$", "viewcst")
#    , (r"^(?P<page>\d+)/getcsts/$", "getcsts")

    , (r"^systems/$", "systems")
    , (r"^(?P<page>\d+/getsystems/$)", GetSystemListView.as_view())
    , (r"^systems/(?P<pk>\d+)/delete", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, "/accounts/denied/")( DeleteView.as_view(model = JrcSystem, template_name = "portadmin/deletesystem.html", success_url = "/portadmin/systems/")) )
    , (r"^system/(?P<id>\d+)", "editsystem")
    , (r"^system/add", "addsystem")

    , (r"^markets/$", login_required( MarketView.as_view() ))
    , (r"^(?P<page>\d+)/getmarkets/$", login_required( ListMarketsView.as_view() ))
    , (r"^market/add/$", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, "/accounts/denied/")( CreateMarketView.as_view() ))
    , (r"^market/(?P<pk>\d+)/$", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, "/accounts/denied/")( UpdateMarketView.as_view() ))
    , (r"^market/(?P<pk>\d+)/delete/$", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, "/accounts/denied/")( DeleteMarketView.as_view() ))

    , (r"^portfolios/$", "portfolios")
    , (r"^(?P<page>\d+)/getportfolios/$", "getportfolios")
    , (r"^portfolio/add/", "addportfolio")
    , (r"^portfolio/(?P<id>\d+)/", "editportfolio")
    , (r"^portfolios/(?P<pk>\d+)/delete/", login_required(DeletePortfolioView.as_view()))

    , (r"^parameters/$", "parameters")
    , (r"^(?P<page>\d+/getparameters/$)", "getparameters")
    , (r"^parameters/(?P<pk>\d+)/delete/", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, "/accounts/denied/")( DeleteView.as_view(model = JrcParameter, template_name = "portadmin/deleteparameter.html", success_url = "/portadmin/parameters/")) )
    , (r"^parameter/add", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, "/accounts/denied/")(CreateParameterView.as_view()))
    , (r"^parameter/(?P<pk>\d+)", permission_required(JrcPermission.TRADINGSYSTEMS_CHANGE, "/accounts/denied/")(UpdateParameterView.as_view()))
#    , (r"^parameter/add", "addparameter")
#    , (r"^parameter/(?P<id>\d+)", "editparameter")

);
